package dockerfile

import (
	"context"
	"github.com/jinzhu/copier"

	"docker/internal/svc"
	"docker/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DockerfilesLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDockerfilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DockerfilesLogic {
	return &DockerfilesLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DockerfilesLogic) Dockerfiles() (resp *types.DockerfileStageResp, err error) {
	all, err := l.svcCtx.DockerfileModel.FindAll(l.ctx)
	var datas []types.DockerfileStageData
	for _, dockerfile := range all {
		var data types.DockerfileStageData
		copier.Copy(&data, &dockerfile)
		data.Id = dockerfile.ID.Hex()
		datas = append(datas, data)
	}

	return &types.DockerfileStageResp{
		Result: types.Result{
			Code:      200,
			Message:   "",
			ExtInfo:   "",
			Timestamp: 0,
		},
		DockerfileStageData: datas,
	}, nil
}
